import 'dart:io';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/auto_makers/perfect_images/id_pic.dart';
import 'package:ytbusiness/page/repair_factory/maintain_qualification.dart';
import 'package:ytbusiness/state/user_role.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';
import 'package:intl/intl.dart';



///修改企业认证
class ModifyPerfect extends StatefulWidget {
  @override
  _ModifyPerfectState createState() => _ModifyPerfectState();
}

class _ModifyPerfectState extends State<ModifyPerfect> {
  bool notEditable = true;//是否不可编辑
  bool personInfo = false;//个人信息
  bool enterprise = false;//企业实名认证
  File iDFront;//身份证正面
  File iDReverse;//身份证反面
  File license;//营业执照
  int role = 2;//用户角色
  List<File> fileList =[];//维修资质图片数组
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setState(() {
      role = Provider.of<UserRole>(context,listen: false).role;
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: (){
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
          backgroundColor: Colors.white,
          appBar:AppBar(
          elevation: 0,
          backgroundColor: Colors.white,
           leading: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: (){
              Navigator.pop(context);
            },
            child: Row(
              children: [
                Container(
                    margin: EdgeInsets.only(left: setWidth(15)),
                    width: setWidth(10),
                    height: setWidth(17),
                    child: Image.asset("assets/images/return.png",fit: BoxFit.cover,)
                ),
              ],
            ),
          ),
          actions: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                  child: GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: (){
                      setState(() {
                        notEditable = !notEditable;
                      });
                    },
                    child: Container(
                      alignment: Alignment.center,
                      margin: EdgeInsets.only(right: setWidth(20)),
                      child: Text(
                        notEditable? "修改":"保存",
                        style: TextStyle(
                            color: YTTheme.theme,
                            fontSize: setSp(15),
                            fontWeight: FontWeight.w600),
                      ),
                    ),
                  ),
                ),
              ],
            )
          ],
        ),
          body:  SingleChildScrollView(
            child: AbsorbPointer(
              absorbing: notEditable,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    margin: EdgeInsets.only( left: setWidth(15),right: setWidth(15)),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          child: Text(
                            "修改企业认证",
                            style: TextStyle(
                                color: Color(0xff321212),
                                fontSize: setSp(21),
                                fontWeight: FontWeight.w600),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: setWidth(3)),
                          child: Text(
                            "向车主介绍一下自己吧",
                            style: TextStyle(
                              color: Color(0xff989898),
                              fontSize: setSp(12),),
                          ),
                        ),
                        SizedBox(
                          height: setWidth(35),
                        )
                      ],
                    ),
                  ),
                  //企业实名认证
                  Container(
                    margin: EdgeInsets.only(left: setWidth(15),right: setWidth(15)),
                    decoration: BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,),
                        )
                    ),
                    padding: EdgeInsets.only(top: setWidth(23),bottom: setWidth(23)),

                    child: GestureDetector(
                      behavior: HitTestBehavior.opaque,
                      onTap: (){
                        FocusScope.of(context).requestFocus(FocusNode());
                        urlPush(context, "yuntu://company_real_name");
                      },
                      child: Row(
                        mainAxisAlignment:MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "企业实名认证",
                            style: TextStyle(
                                color: YTTheme.theme,
                                fontSize: setSp(15),
                                fontWeight: FontWeight.w600),
                          ),
                          Row(
                            children: [
                              Container(
                                height: setWidth(5),
                                width: setWidth(5),
                                decoration: BoxDecoration(
                                    color: Color(0xffFF3636),
                                    borderRadius: BorderRadius.circular(20)

                                ),
                              ),
                              SizedBox(
                                width: setWidth(5),
                              ),
                              Text(
                                "未认证",
                                style: TextStyle(
                                  color: Color(0xff989898),
                                  fontSize: setSp(15),),
                              ),
                              SizedBox(
                                width: setWidth(10),
                              ),
                              Container(
                                width: setWidth(9),
                                height: setWidth(16),
                                child: Image.asset("assets/images/pay_go.png",fit: BoxFit.cover,),
                              )

                            ],
                          )
                        ],
                      ),
                    ),
                  ),

                  //个人实名认证
                  Container(
                    margin: EdgeInsets.only(left: setWidth(15),right: setWidth(15)),
                    decoration: BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,),
                        )
                    ),
                    padding: EdgeInsets.only(top: setWidth(23),bottom: setWidth(23)),

                    child: GestureDetector(
                      behavior: HitTestBehavior.opaque,
                      onTap: (){
                        FocusScope.of(context).requestFocus(FocusNode());
                        urlPush(context, "yuntu://personal_real_name");
                      },
                      child: Row(
                        mainAxisAlignment:MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "个人实名认证",
                            style: TextStyle(
                                color: YTTheme.theme,
                                fontSize: setSp(15),
                                fontWeight: FontWeight.w600),
                          ),
                          Row(
                            children: [
                              Container(
                                height: setWidth(5),
                                width: setWidth(5),
                                decoration: BoxDecoration(
                                    color: Color(0xffFF3636),
                                    borderRadius: BorderRadius.circular(20)

                                ),
                              ),
                              SizedBox(
                                width: setWidth(5),
                              ),
                              Text(
                                "未认证",
                                style: TextStyle(
                                  color: Color(0xff989898),
                                  fontSize: setSp(15),),
                              ),
                              SizedBox(
                                width: setWidth(10),
                              ),
                              Container(
                                width: setWidth(9),
                                height: setWidth(16),
                                child: Image.asset("assets/images/pay_go.png",fit: BoxFit.cover,),
                              )

                            ],
                          )
                        ],
                      ),
                    ),
                  ),

                  //开户行认证
                  Container(
                    margin: EdgeInsets.only(left: setWidth(15),right: setWidth(15),top: setWidth(28),bottom: setWidth(40)),
                    child: Row(
                      children: [
                        Text(
                          "开户行认证",
                          style: TextStyle(
                              color: YTTheme.theme,
                              fontSize: setSp(15),
                              fontWeight: FontWeight.w600),
                        )
                      ],
                    ),
                  ),

                  Container(
                    margin: EdgeInsets.only( left: setWidth(15),right: setWidth(15)),
                    child: Column(
                      children: [
                        //账户名称
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("账户名称",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      inputFormatters: [
                                        WhitelistingTextInputFormatter(RegExp("[0-9.]|[a-zA-Z]")),//只允许输入数字字母
                                      ],
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入账户名称",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        //开户行
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("开户行",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入开户行",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        //银行账户
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("银行账户",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入银行账户",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top:setWidth(10)),
                          child: Row(
                            children: [
                              Container(
                                child: Image.asset("assets/images/warning.png",fit: BoxFit.cover,),
                                width: setWidth(15),
                                height: setWidth(15),
                              ),
                              SizedBox(
                                width: setWidth(10),
                              ),
                              Text(
                                "用于资金账户提现，请谨慎填写",
                                style: TextStyle(
                                    color: Color(0xff999999),
                                    fontSize: setSp(12)),
                              )
                            ],
                          ),
                        ),

                        //发票信息
                        Container(
                          margin: EdgeInsets.only(top: setWidth(36),bottom: setWidth(40)),
                          child:Row(
                            children: [
                              Text(
                                "发票信息",
                                style: TextStyle(
                                    color: YTTheme.theme,
                                    fontSize: setSp(15),
                                    fontWeight: FontWeight.w600),
                              )
                            ],
                          ),
                        ),

                        //发票抬头
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("发票抬头",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入发票抬头",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        //纳税人识别号
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("纳税人识别号",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入纳税人识别号",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        //开户行及账号
                        Container(
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("开户行及账号",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入银行账户",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        //地址、电话
                        Container(
                          padding: EdgeInsets.only(top: setWidth(10),bottom: setWidth(10)),
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("地址、电话",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: null,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,

                                      decoration: InputDecoration(
                                        isDense:true,
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入地址电话",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        //电子邮箱
                        Container(
                          decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  color: Color(0xffF0F0F0),
                                  width: 0.5,),
                              )
                          ),
                          padding: EdgeInsets.only(top: setWidth(5),bottom: setWidth(5)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                child: Text("电子邮箱",style: TextStyle(color: Color(0xff321212),fontSize: setSp(15)),),
                              ),
                              SizedBox(
                                width: setWidth(50),
                              ),
                              Expanded(
                                  child: Container(
                                    child: TextField(
                                      textAlign: TextAlign.end,
                                      maxLines: 1,
                                      keyboardType: TextInputType.multiline,
                                      autofocus: false,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        hintText: "请输入电子邮箱",
                                        hintStyle: TextStyle(color: Color(0xff989898),fontSize: setSp(16)),

                                      ),
                                    ),
                                  )),
                            ],
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top:setWidth(10)),
                          child: Row(
                            children: [
                              Container(
                                child: Image.asset("assets/images/warning.png",fit: BoxFit.cover,),
                                width: setWidth(15),
                                height: setWidth(15),
                              ),
                              SizedBox(
                                width: setWidth(10),
                              ),
                              Text(
                                "用于接收电子发票",
                                style: TextStyle(
                                    color: Color(0xff999999),
                                    fontSize: setSp(12)),
                              )
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  //完善修理厂信息  显示维修资质
                  Offstage(
                    offstage: role != 1,
                    child: Container(
                        margin: EdgeInsets.only( left: setWidth(15),top: setWidth(37),right: setWidth(15)),
                        child: MaintainQualification(getImage:_galleryImage,fileList:fileList)),
                  ),
                  SizedBox(
                    height: setWidth(80),
                  ),
                ],
              ),
            ),
          ),

      ),
    );
  }

  //从相册选择图片
  _galleryImage() async {
    await ImagePicker.pickImage(source: ImageSource.gallery).then((value){
      if(value != null){
        setState(() {
          fileList.add(value);
        });
      }
    });
  }


}
